package br.com.medmark.model.hibernate.dao;

import javax.persistence.NoResultException;
import javax.persistence.TypedQuery;

import br.com.medmark.model.hibernate.Administrador;

public class AdministradorDAO extends GenericoDAOImpl<Administrador>{
	

private static final long serialVersionUID = 1L;
private static AdministradorDAO admDAO = null;
	
	private AdministradorDAO(){
		
	}
	
	public static AdministradorDAO getInstance(){
		
		if ( admDAO == null) {
			admDAO = new AdministradorDAO();
		}
	
		return admDAO;
		
	}
	public Administrador getAdministrador(String login, String senha) {
		String sql = "FROM Administrador c Where c.login = :login and c.senha = :senha";
		
		TypedQuery<Administrador> query = this.entityManager.createQuery(sql, Administrador.class);
		query.setParameter("login", login);
		query.setParameter("senha", senha);
		
		try {
			return query.getSingleResult();
		} catch (NoResultException ex) {
			return null;
		}
	}
	
	public Administrador getAdministrador(Long codigo) {
		String sql = "FROM Administrador c Where c.codigo = :codigo";
		
		TypedQuery<Administrador> query = this.entityManager.createQuery(sql, Administrador.class);
		query.setParameter("codigo", codigo);
		
		try {
			return query.getSingleResult();
		} catch (NoResultException ex) {
			return null;
		}
	}

}
